package com.prd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntBudgetCourseMapper;
import com.prd.model.EntBudgetCourse;
import com.prd.model.LoginUser;
import com.prd.service.EntBudgetCourseService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EntBudgetCourseServiceImpl extends ServiceImpl<EntBudgetCourseMapper, EntBudgetCourse> implements EntBudgetCourseService {

    @Autowired
    private EntBudgetCourseMapper entBudgetCourseMapper;

    @Override
    public int insertInfo(EntBudgetCourse entBudgetCourse) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entBudgetCourse);
        return entBudgetCourseMapper.insert(entBudgetCourse);
    }

    @Override
    public int updateInfo(EntBudgetCourse entBudgetCourse) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entBudgetCourse);
        return entBudgetCourseMapper.updateById(entBudgetCourse);
    }
}
